Guide
Install Extensions
Install the dio-wallet
extension.
Install the SDK
We use @dioxide-js/detect-provider
to check the initialization status of the wallet API, ensuring that the interface can be accessed after the API initialization is complete.
$ // or yarn add @dioxide-js/detect-provider $ npm install @dioxide-js/detect-provider --save
CDN:
https://unpkg.com/@dioxide-js/detect-provider/dist/detect-provider.umd.js
Usage
Usage in ES module:
import detectProvider from "@dioxide-js/detect-provider";
detectProvider({ timeout: 4000 }).then((dioxide) => {
if (dioxide) {
// From now on, you can interact with dio-wallet
// And this will always be true:
// dioxide === window.dioxide
startApp(dioxide); // initialize your app
} else {
console.log('Please install Dioxide wallet!');
}
})
function startApp(dioxide) {
// Call rpc method like below:
// dioxide.request({method, params}).then(data).catch(ex)
dioxide.request({method: "network"}).then(network => {
console.log(network)
}).catch(ex => console.log(ex))
// Listen event emitted after dio-wallet status change
// dioxide.on('<diox_event>', handler:(data: any) => void)
dixoide.on('network_changed', (newNetwork) => {
console.log(newNetwork)
})
dixoide.on("connected\_address\_changed", (account: string\[\]) => {
console.log(account\[0\])
})
}
Usage in Browser:
<script src="https://unpkg.com/@dioxide-js/detect-provider/dist/detect-provider.umd.js"></script>
<script type="text/javascript">
window.dioxideDetectProvider({ timeout: 3000 }).then((diox) => {
if (diox) {
// Do what you want from now
// ...
} else {
console.error("Dio-wallet not found, please install Diox-wallet");
}
});
</script>
Please use the WalletJS_API
after initialization of the SDK.
import detectProvider from "@dioxide-js/detect-provider";
detectProvider().then((diox) => {
// do what you want with diox
})